<?php
      header("content-type:text/html;charset=utf8;");
# 终止逻辑 , 如果没有用户提交的数据，那么终止代码;
      $usr = @$_GET["username"];
      $pwd = @$_GET["password"];
      if(!$usr || !$pwd){
            die("");
      }

# 链接数据库 
      $host     = "localhost";
      $username = "root";
      $password = "root";
      $dbname   = "mydate";

      $conn = mysqli_connect($host,$username,$password,$dbname);

      if(!$conn){
            die("数据库连接失败" . mysqli_error());
      }
# 判定数据库之中是否已经存在了;
      
      $sql_select = "SELECT username FROM userlist WHERE username='$usr'";
      // 辨别查询结果之中有多少条数据


      $res = mysqli_query($conn,$sql_select);

      if(mysqli_num_rows( $res ) > 0 ) {
            die("用户名重名");
      }

# 插入数据
      $pwd = md5($pwd);
      $sql_insert = "INSERT INTO userlist (
            username , password 
      ) VALUES (
            '$usr' , '$pwd'
      ) ";
      if(mysqli_query($conn,$sql_insert)){
            echo '<script>
                  location.href = "http://localhost/seven/XDW/meizu_project/src/login.html";
            </script>';
      }else{
            echo '<script>
                  location.href = "http://localhost/seven/XDW/meizu_project/src/regiter.html";
                  alert(注册错误！);
            </script>';
      }

?>